﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;
using System.Xml;
using System.Xml.Xsl;

public partial class ext_test : Page
{
    MyDbHelper mydb = new MyDbHelper();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //LodUser();
        }
    }

    private void LodUser()
    {
        DataSet ds = mydb.DM_GetDateSet(@"select u.usercode,u.username,l.* from sys_loginlog l inner join sys_loginuser u on u.userid = l.userid
                    where 1=1 order by logindatetime desc");
        this.Store1.DataSource = ds;
        this.Store1.DataBind();
    }
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        //X.Msg.Alert("提示", "加载成功！").Show();
        LodUser();
    }
    protected void MyData_Refresh(object sender, StoreReadDataEventArgs e)
    {
        this.LodUser();
    }
    protected void Command(object sender, DirectEventArgs e)
    {
        var command = e.ExtraParams["command"].ToString();
        var Id = e.ExtraParams["Id"].ToString();
        X.Msg.Alert("Command", Id + " : " + command).Show();
        if (command == "Delete")
        {
            //this.txtuser.Text = command;
            
        }
        
        
    }
    [DirectMethod(Namespace = "CompanyX")]
    public void Post(string command,string id)
    {

    }
    //导出EXCEL
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        string format = this.FormatType.Value.ToString();

        XmlNode xml = e.Xml;

        this.Response.Clear();

        switch (format)
        {
            case "xml":
                string strXml = xml.OuterXml;
                this.Response.AddHeader("Content-Disposition", "attachment; filename=" + this.Title + ".xml");
                this.Response.AddHeader("Content-Length", strXml.Length.ToString());
                this.Response.ContentType = "application/xml";
                this.Response.Write(strXml);

                break;
            case "xls":
                this.Response.ContentType = "application/vnd.ms-excel";
                this.Response.AddHeader("Content-Disposition", "attachment; filename="+this.Title+".xls");
                XslCompiledTransform xtExcel = new XslCompiledTransform();
                xtExcel.Load(Server.MapPath("Excel.xsl"));
                xtExcel.Transform(xml, null, Response.OutputStream);

                break;
            case "csv":
                this.Response.ContentType = "application/octet-stream";
                this.Response.AddHeader("Content-Disposition", "attachment; filename=" + this.Title + ".csv");
                XslCompiledTransform xtCsv = new XslCompiledTransform();
                xtCsv.Load(Server.MapPath("Csv.xsl"));
                xtCsv.Transform(xml, null, Response.OutputStream);

                break;
        }

        this.Response.End();
    }
}